// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_ok.java

package purchase.apply;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class check_ok extends HttpServlet
{

	public check_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		counter count = new counter(dbApplication);
		try
		{
			nseer_db_backup1 purchase_db = new nseer_db_backup1(dbApplication);
			if (purchase_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String apply_ID = request.getParameter("apply_ID");
				String config_ID = request.getParameter("config_ID");
				String designer = request.getParameter("designer");
				String register = request.getParameter("register");
				String register_time = request.getParameter("register_time");
				String checker = request.getParameter("checker");
				String checker_ID = request.getParameter("checker_ID");
				String check_time = request.getParameter("check_time");
				String bodyb = new String(request.getParameter("remark").getBytes("UTF-8"), "UTF-8");
				String remark = exchange.toHtml(bodyb);
				String sql6 = (new StringBuilder("select id from purchase_workflow where object_ID='")).append(apply_ID).append("' and ((check_tag='0' and config_ID<'").append(config_ID).append("') or (check_tag='1' and config_ID='").append(config_ID).append("'))").toString();
				ResultSet rs6 = purchase_db.executeQuery(sql6);
				if (!rs6.next())
				{
					String sql8 = (new StringBuilder("select * from purchase_apply where apply_ID='")).append(apply_ID).append("' and check_tag='0'").toString();
					ResultSet rs8 = purchase_db.executeQuery(sql8);
					if (rs8.next())
					{
						String sql = (new StringBuilder("update purchase_apply set designer='")).append(designer).append("',register='").append(register).append("',register_time='").append(register_time).append("',remark='").append(remark).append("',checker='").append(checker).append("',check_time='").append(check_time).append("' where apply_ID='").append(apply_ID).append("'").toString();
						purchase_db.executeUpdate(sql);
						String sql9 = (new StringBuilder("update purchase_workflow set checker='")).append(checker).append("',checker_ID='").append(checker_ID).append("',check_time='").append(check_time).append("',check_tag='1' where object_ID='").append(apply_ID).append("' and config_ID='").append(config_ID).append("'").toString();
						purchase_db.executeUpdate(sql9);
						sql9 = (new StringBuilder("select id from purchase_workflow where object_ID='")).append(apply_ID).append("' and check_tag='0'").toString();
						ResultSet rset = purchase_db.executeQuery(sql9);
						if (!rset.next())
						{
							sql9 = (new StringBuilder("update purchase_apply set check_tag='1' where apply_ID='")).append(apply_ID).append("'").toString();
							purchase_db.executeUpdate(sql9);
						}
						response.sendRedirect("purchase/apply/check_ok.jsp?finished_tag=0");
					} else
					{
						response.sendRedirect("purchase/apply/check_ok.jsp?finished_tag=1");
					}
				} else
				{
					response.sendRedirect("purchase/apply/check_ok.jsp?finished_tag=2");
				}
				purchase_db.commit();
				purchase_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
